package de.tub.bazinga.ymca;

import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;

import de.tub.bazinga.object.TargetDefinition;

public class TargetStoreImpl implements ITargetStore {

	Map<Integer, Set<TargetDefinition>> targets;

	public TargetStoreImpl(Map<Integer, Set<TargetDefinition>> targets) {
		super();
		this.targets = targets;
	}

	public TargetStoreImpl() {
		targets = new HashMap<Integer, Set<TargetDefinition>>();
	}

	@Override
	public void addTarget(Integer key, Set<TargetDefinition> td) {
		targets.put(key, td);
	}

	@Override
	public Set<TargetDefinition> getTargetDefinitions(int time) {
		List<Integer> keys = new ArrayList<Integer>(targets.keySet());
		Collections.sort(keys);

		Integer lastKey = keys.get(0);
		for (Integer key : keys) {
			if (key > time) {
				break;
			}
			lastKey = key;
		}

		return targets.get(lastKey);
	}
}
